package org.elasticsearch.commons;

import org.nlpcn.commons.lang.pinyin.PinyinFormat;


import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class Pinyin {
    public Pinyin() {
    }

    public static List<String> pinyin(String str) {
        return PinyinUtil.INSTANCE.convert(str, PinyinFormat.TONELESS_PINYIN_FORMAT);
    }

    public static Map<String, List<String>> multiPinyin(String str) {
        return MultiPinyinUtil.INSTANCE.convert(str, PinyinFormat.TONELESS_PINYIN_FORMAT);
    }

    public static List<String> firstChar(String str) {
        return PinyinUtil.INSTANCE.convert(str, PinyinFormat.ABBR_PINYIN_FORMAT);
    }

    public static List<String> unicodePinyin(String str) {
        return PinyinUtil.INSTANCE.convert(str, PinyinFormat.UNICODE_PINYIN_FORMAT);
    }

    public static List<String> tonePinyin(String str) {
        return PinyinUtil.INSTANCE.convert(str, PinyinFormat.DEFAULT_PINYIN_FORMAT);
    }

    public static String list2String(List<String> list, String spearator) {
        StringBuilder sb = new StringBuilder();
        boolean flag = true;
        Iterator var4 = list.iterator();

        while(var4.hasNext()) {
            String string = (String)var4.next();
            if (string == null) {
                string = "NULL";
            }

            if (flag) {
                sb.append(string);
                flag = false;
            } else {
                sb.append(spearator);
                sb.append(string);
            }
        }

        return sb.toString();
    }

    public static String list2String(List<String> list) {
        return list2String(list, " ");
    }

    public static void insertPinyin(String word, String[] pinyins) {
        PinyinUtil.INSTANCE.insertPinyin(word, pinyins);
    }

    public static String list2StringSkipNull(List<String> list) {
        return list2StringSkipNull(list, " ");
    }

    public static String list2StringSkipNull(List<String> list, String spearator) {
        StringBuilder sb = new StringBuilder();
        boolean flag = true;
        Iterator var4 = list.iterator();

        while(var4.hasNext()) {
            String string = (String)var4.next();
            if (string != null) {
                if (flag) {
                    sb.append(string);
                    flag = false;
                } else {
                    sb.append(spearator);
                    sb.append(string);
                }
            }
        }

        return sb.toString();
    }
}